package com.dataart.training.crimequalification.facesutils;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

public class FacesMessageHandlingUtils {

    /**
     * Adds a message to a JSF component specified by its server id.
     *
     * @param componentId JSF component server id
     * @param message     message to add to the component
     */
    public void addMessageToComponent(String componentId, String message) {
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(context.getViewRoot().findComponent(componentId).getClientId(), new FacesMessage(message));
    }

}
